package com.project.xsf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.common.entity.PageVo;
import com.project.common.utils.Serial;
import com.project.xsf.controller.MApplyController;
import com.project.xsf.entity.MApply;
import com.project.xsf.entity.MDesignProcedure;
import com.project.xsf.mapper.MApplyMapper;
import com.project.xsf.service.MApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class MApplyImpl implements MApplyService {
    @Autowired
    MApplyMapper mApplyMapper;
    @Override
    public int addMApply(MApply[] record) throws IOException {
        Serial serial = new Serial();
        serial.addUser("mApplyId","300");
        String number = serial.getNumber("mApplyId", "300", null, null, null);

        for(int i=0;i<record.length;i++){
            MApply mApply = record[i];
            mApply.setCheckTag("S001-0");
            mApply.setManufactureTag("P001-0");
            mApply.setApplyId(number);
            mApplyMapper.insertSelective(mApply);
        }
        return 0;
    }

    @Override
    public PageVo<MApply> queryMApplyNoCheck(Map<String,String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));

        PageHelper.startPage(pageNum,pageSize);
        List<MApply> mApplies = mApplyMapper.queryMApplyNoCheck();
        PageInfo pageInfo = new PageInfo(mApplies);

        PageVo<MApply> pageVo = new PageVo<MApply>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }

    @Override
    public List<MApply> queryMApplyByApplyId(String applyId) {
        return mApplyMapper.queryMApplyByApplyId(applyId);
    }

    @Override
    public int updateByMApplyId(MApply record) {
        return mApplyMapper.updateByMApplyId(record);
    }

    @Override
    public PageVo<MApply> queryMApplyAll(Map<String, String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));

        PageHelper.startPage(pageNum,pageSize);
        List<MApply> mApplies = mApplyMapper.queryMApplyAll();
        PageInfo pageInfo = new PageInfo(mApplies);

        PageVo<MApply> pageVo = new PageVo<MApply>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }

    @Override
    public PageVo<MApply> queryMApplyCheck(Map<String, String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));

        PageHelper.startPage(pageNum,pageSize);
        List<MApply> mApplies = mApplyMapper.queryMApplyCheck();
        PageInfo pageInfo = new PageInfo(mApplies);

        PageVo<MApply> pageVo = new PageVo<MApply>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }

    @Override
    public MApply selectByPrimaryKey(Integer id) {
        return mApplyMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(MApply record) {
        return mApplyMapper.updateByPrimaryKeySelective(record);
    }
}
